#include <SDL_rotozoom.h>
#include <SDL_image.h>

#include "surface.h"

#include <iostream>

using namespace std;

Surface::Surface(string filename):smoothing(true)
{
	SDL_Surface *tmp;
	tmp = IMG_Load(filename.c_str());
	if(tmp == NULL)
	{
		cerr << "No se puede cargar " << ": " << SDL_GetError() << endl;
		exit(-1);
	}

	SDL_SetColorKey(tmp,SDL_SRCCOLORKEY | SDL_RLEACCEL,0xFF00FF);
	surface = SDL_DisplayFormatAlpha(tmp);
	SDL_FreeSurface(tmp);

	if(surface == NULL)
	{
		cerr << "Error al convertir " << " al formato de la pantalla: "
			<< SDL_GetError() << endl;
		exit(-1);
	}
}

Surface::Surface(SDL_Surface *a_surface):smoothing(true)
{
	surface = a_surface;
}

Surface::~Surface()
{
	if(surface!=NULL)
		SDL_FreeSurface(surface);
}

Surface* Surface::getRotate(const float angle)const
{
	return new Surface(rotozoomSurface(surface,angle,1,smoothing));
}

Surface* Surface::getZoom(const float zoom)const
{
	return new Surface(rotozoomSurface(surface,0,zoom,smoothing));
}

Surface* Surface::getRotozoom(const float angle,const float zoom)const
{
	return new Surface(rotozoomSurface(surface,angle,zoom,smoothing));
}

Surface* Surface::getZoomXY(const float zoomx,const float zoomy)const
{
	return new Surface(zoomSurface(surface,zoomx,zoomy,smoothing));
}

Surface* Surface::getRotozoomXY(const float angle,
		const float zoomx, const float zoomy)const
{
	return new Surface(rotozoomSurfaceXY(surface,angle,zoomx,zoomy,smoothing));
}

Surface* Surface::getShrink(const int x,const int y)const
{
	//return new Surface(shrinkSurface(surface,x,y));
	return NULL;
}

Surface* Surface::getShrink(const int f)const
{
	//return new Surface(shrinkSurface(surface,f,f));
	return NULL;
}

Surface* Surface::getHorizontalFlip()const
{
	return new Surface(rotozoomSurfaceXY(surface,0,-1,1,false));
}

Surface* Surface::getVerticalFlip()const
{
	return new Surface(rotozoomSurfaceXY(surface,0,1,-1,false));
}

Surface* Surface::getAlphaBleding(const Uint8 alpha)const
{
	//TODO
	return NULL;
}

Surface* Surface::getChangeColor(Uint32 color)const
{
	//TODO
	return NULL;
}

Surface* Surface::getFade(Uint32 color)const
{
	//TODO
	return NULL;
}

/*
*/
